<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签必须放在最前面，任何其他内容都必须跟随其后！ -->
    <title>Ymall</title>
    <!-- Bootstrap样式 -->
    <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="jquery/jquery-3.4.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    <!--前端渲染-->
    <script src="js/jsrender.js"></script>

    <link rel="stylesheet" href="css/Ymall.css">
    <link rel="stylesheet" href="css/Mall.css">
</head>
<body>
<!-- navbar导航栏 -->
<nav class="navbar navbar-default">
    <div class="container-fluid" id="navbar">
        <div class="row clearfix">
            <div class="col-md-1 column">
            </div>
            <div class="col-md-10 column">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                            data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"><img class="img-logo" src="img/logol.png" alt=""></a>
                </div>

                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a href="Ymall.html"><span class="span-font">首页</span><span class="sr-only">(current)</span></a>
                        </li>
                        <li><a href="Mall.html"><span class="span-font">购物商城</span> </a></li>
                        <li><a href="#"><span class="span-font">求购商城</span> </a></li>
                        <li><a href="cart.html"><span class="span-font">购物车</span> </a></li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                               aria-haspopup="true" aria-expanded="false"><span class="span-font">反馈与意见</span> <span
                                    class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#"><span class="span1-font">反馈</span></a></li>
                                <li role="separator"  class="divider"></li>
                                <li><a href="#"><span class="span1-font">意见</span></a></li>
                            </ul>
                        </li>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                               aria-haspopup="true" aria-expanded="false"><span class="span-font">联系我们</span> <span
                                    class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="#"><span class="span1-font">电话联系</span></a></li>
                                <li role="separator"  class="divider"></li>
                                <li><a href="#"><span class="span1-font">邮箱联系</span></a></li>
                            </ul>
                        </li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li id="login"><a href="Login.html"><span class="span-font">登录</span></a></li>
                        <li id="register"><a href="Register.html"><span class="span-font">注册</span></a></li>
                    </ul>
                    <form class="navbar-form navbar-right">
                        <div class="form-group">
                            <input type="text" id="content" class="form-control" placeholder="Search">
                        </div>
                        <!-- <button type="submit" class="btn btn-default"><img class="img-search" src="img/" alt=""></button> -->
                        <button type="button" class="btn btn-default" id="search"><img class="img-search"
                                                                                       src="img/search_icon.png" alt="">
                        </button>
                    </form>
                </div>
            </div>
            <div class="col-md-1 column">
            </div>
        </div>
    </div>
</nav>

<!--goods商品信息-->
<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-1 column">
        </div>
        <div class="col-md-10 column">
            <div class="container-fluid">
                <div class="row clearfix">
                    <div class="col-md-3 column" id="goods-information">
                        <div class="thumbnail" style="margin-right: 40%">
                            <div class="caption">
                                <ul class="goods-ul">
                                    <h3 class="goods-h3"><a href="">数码科技
                                        <ul class="goods-ul1">
                                            <li><span>数码相机</span> <span>手机</span> <span>电脑</span></li>
                                            <li><span>单反相机</span> <span>平板</span> <span>笔记本</span></li>
                                        </ul>
                                    </a></h3>

                                    <h3 class="goods-h3"><a href="">影视家电
                                        <ul class="goods-ul1">
                                            <li><span>手机</span><span>数码相机</span> <span>手机</span></li>
                                            <li>电脑</li>
                                            <li><span>平板</span> <span>相机</span></li>
                                            <li><span>数码相机</span> <span>单反相机</span></li>
                                        </ul>
                                    </a></h3>

                                    <h3 class="goods-h3"><a href="">书籍文具
                                        <ul class="goods-ul1">
                                            <li>童话书</li>
                                            <li>笑话书</li>
                                            <li>编程书</li>
                                            <li>玄幻小说</li>
                                            <li>修仙小说</li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                        </ul>
                                    </a></h3>

                                    <h3 class="goods-h3"><a href="">摄影远足
                                        <ul class="goods-ul1">
                                            <li>摄像机</li>
                                            <li>翘首</li>
                                            <li>登山鞋</li>
                                            <li>登山包</li>
                                            <li>地图</li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                        </ul>
                                    </a></h3>

                                    <h3 class="goods-h3"><a href="">运动服饰
                                        <ul class="goods-ul1">
                                            <li>服饰</li>
                                            <li>休闲裤</li>
                                            <li>休闲衣</li>
                                            <li>运动裤</li>
                                            <li>运动衣</li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                        </ul>
                                    </a></h3>

                                    <h3 class="goods-h3"><a href="">其他
                                        <ul class="goods-ul1">
                                            <li>手机</li>
                                            <li>电脑</li>
                                            <li>平板</li>
                                            <li>数码相机</li>
                                            <li>单反相机</li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                            <li></li>
                                        </ul>
                                    </a></h3>

                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <div class="row clearfix">
                            <div class="col-md-2 column">
                            </div>
                            <div class="col-md-10 column">
                                <div class="col-md-4 column">
                                    <div class=" goods" id="goods0" style="margin-left: 10%;">
                                    </div>
                                    <div class=" goods" id="goods3" style="margin-left: 10%; margin-top: 20%;">
                                    </div>
                                    <div class=" goods" id="goods6" style="margin-left: 10%; margin-top: 20%;">
                                    </div>
                                </div>
                                <div class="col-md-4 column">
                                    <div class=" goods" id="goods1" style="margin-left: 10%;">
                                    </div>
                                    <div class=" goods" id="goods4" style="margin-left: 10%; margin-top: 20%;">
                                    </div>
                                    <div class=" goods" id="goods7" style="margin-left: 10%; margin-top: 20%;">
                                    </div>
                                </div>
                                <div class="col-md-4 column">
                                    <div class=" goods" id="goods2" style="margin-left: 10%;">
                                    </div>
                                    <div class=" goods" id="goods5" style="margin-left: 10%; margin-top: 20%;">
                                    </div>
                                    <div class=" goods" id="goods8" style="margin-left: 10%; margin-top: 20%;">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="col-md-1 column">
        </div>
    </div>
</div>

<!--pagination分页-->
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <ul class="pagination">
                <li>
                    <a href="#"><</a>
                </li>
                <li>
                    <a href="#">1</a>
                </li>
                <li>
                    <a href="#">2</a>
                </li>
                <li>
                    <a href="#">3</a>
                </li>
                <li>
                    <a href="#">4</a>
                </li>
                <li>
                    <a href="#">5</a>
                </li>
                <li>
                    <a href="#">></a>
                </li>
            </ul>
        </div>
    </div>
</div>

<!--copyright版权说明-->
<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-1 column">
        </div>
        <div class="col-md-10 column">
            <div id="copyRight-frame">
                <strong>Copyright © 2017-2200.Company name All rights reserved.</strong>
            </div>
        </div>
        <div class="col-md-1 column">
        </div>
    </div>
</div>

<!--[Product pid-1，-->
<!--pname-计算机网络 课本”，-->
<!--price=6.6，-->
<!--sort-0，-->
<!--count=10，-->
<!--info=计算机网络课本，-->
<!--主编：文鸿.…吉林大学出版社，sales=2，-->
<!--uid=1，-->
<!--images=null'}-->


<script id="theTmpl" type="text/x-jsrender">
    <div class="thumbnail">
        <img alt="300x200" src="{{:images}}" style="width:300px; height:250px" />
        <div class="caption">
            <h3 style="margin-left:10%">{{:pname}}</h3>
            <p style="margin-left:33%">￥{{:price}}</p>
            <p style="margin-left:10%">{{:info}}</p>
            <p>
                <a class="btn btn-primary" onclick="add({{:pid}})">Buy</a>
            </p>
        </div>
    </div>
</script>

<script>
    var add = function (pid) {
        $.get("http://localhost:8080//ycumall/CartServlet?method=add", "pid=" + pid, function (data) {
            if (data.status == 400) {
                alert("库存为0, 添加失败");
            } else {
                alert("添加成功!");
            }

        });
    }

    var template = $.templates("#theTmpl");
    $.get("http://localhost:8080/ycumall/ProductServlet?method=queryAll", function (data) {
        var len = data.data.length;

        for (var i = 0; i < len; i++) {
            var htmlOutput = template.render(data.data[i]);
            $("#goods" + i).html(htmlOutput);
        }
    });

    $.get("http://localhost:8080/ycumall/UserServlet?method=getInfo", function (data) {
        if (data.data != null) {
            $("#login").html('<a href="#" style="color: black;font-size: 16px;">' + data.data + '</a>');
            $("#register").html('<a href="http://localhost:8080/ycumall/UserServlet?method=outLogin" style="color: black;font-size: 16px;">登出</a>');
            console.log(data.data);
        }
    });

    $("#search").click(function () {
        var likeName = $("#content").val();
        console.log(likeName);
        if (!(likeName == "")) {
            $.ajax({
                type: "POST",
                url: "http://localhost:8080/ycumall/ProductServlet?method=likeQuery&name=" + likeName,
                error: function (request) {  //失败的话
                    alert("查询失败!");
                },
                success: function (data) {  //成功
                    if (data.data != null) {
                        console.log(data.data);
                        window.location.href = "search.html?name=" + likeName;
                    } else {
                        alert("没有该商品!");
                    }
                }

            });
        }else{
            alert("请输入查找商品信息");
        }

    });
</script>

</body>
</html>